//
//  LMSettingTableViewController.m
//  彩票
//
//  Created by apple on 15/9/23.
//  Copyright (c) 2015年 李明. All rights reserved.
//

#import "LMSettingTableViewController.h"
#import "LMSettingObject.h"
#import "LMSettingTableViewCell.h"
#import "ViewController.h"
#import "MBProgressHUD+Extend.h"
#import "LMBaseSettingViewController.h"
@interface LMBaseSettingViewController ()



@end

@implementation LMBaseSettingViewController


- (NSMutableArray *)settingitemArray
{
    if (_settingitemArray==nil) {
        _settingitemArray = [NSMutableArray array];
    }
    return _settingitemArray;
}


- (instancetype)init
{
    if (self =[super initWithStyle:UITableViewStyleGrouped]) {
        
    }
    return self;
}



- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"bg"]];
    

}
#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    return self.settingitemArray.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    
    LMSettingObjectGroup *array = self.settingitemArray[section];
    return array.items.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    
    LMSettingTableViewCell *cell = [LMSettingTableViewCell cellWithTableView:tableView];
    LMSettingObjectGroup *group = self.settingitemArray[indexPath.section];
    LMSettingObject *object = group.items[indexPath.row];
    cell.object = object;
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    
    LMSettingObjectGroup *group = self.settingitemArray[indexPath.section];
    LMSettingObject *object = group.items[indexPath.row];
    
    if(object.operationBlock)
    {
        object.operationBlock();
    }
    
    if (object.vcClass!=nil) {
        id vc =[[object.vcClass alloc] init];
        [vc setTitle:object.title];
        [self.navigationController pushViewController:vc animated:YES];
        
    }
}

- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section
{
    LMSettingObjectGroup *group = self.settingitemArray[section];
    return  group.footTitle;
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    LMSettingObjectGroup *group = self.settingitemArray[section];
    return  group.headTitle;
}

@end
